//
//  Slider.m
//  UI06_播放界面
//
//  Created by dllo on 15/7/17.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "Slider.h"

@implementation Slider

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _minTime = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, frame.size.width / 6, frame.size.height)];
        _maxTime = [[UILabel alloc] initWithFrame:CGRectMake(frame.size.width * 5 / 6, 0, frame.size.width / 6, frame.size.height)];
        _slider = [[UISlider alloc] initWithFrame:CGRectMake(frame.size.width / 6, 0, frame.size.width * 4 / 6, frame.size.height)];
        _minTime.text = @"00:00";
        _maxTime.font = [UIFont systemFontOfSize:13];
        _minTime.font = [UIFont systemFontOfSize:13];
        _maxTime.textAlignment = NSTextAlignmentCenter;
        _minTime.textAlignment = NSTextAlignmentCenter;
        _maxTime.textColor = [UIColor whiteColor];
        _minTime.textColor = [UIColor whiteColor];
        _slider.minimumValue = 0;
        _slider.minimumTrackTintColor = [UIColor cyanColor];
        _slider.maximumTrackTintColor = [UIColor whiteColor];
        [self addSubview:_slider];
        [self addSubview:_maxTime];
        [self addSubview:_minTime];
        [_slider addTarget:self action:@selector(slider:) forControlEvents:UIControlEventValueChanged];
    }
    return self;
}


- (void)slider:(UISlider *)slider

{
    NSMutableString *minM = [NSMutableString stringWithString:[_minTime.text substringToIndex:2] ];
    NSString *minS = [_minTime.text substringFromIndex:3];
    int minMM = minM.intValue;
    int minSS = minS.intValue;
    minSS = minSS + 1;
    int temp9 = minSS;
    minSS = temp9 % 60;
    minMM =  minMM + temp9 / 60;
    NSMutableString *temp1 = [NSMutableString stringWithFormat:@"0%d", minMM];
    NSString *temp2 = [NSString string];
    if (minSS >= 10) {
            temp2 = [NSString stringWithFormat:@"%d", minSS];
    }else{
            temp2 = [NSString stringWithFormat:@"0%d", minSS];
    }
    [temp1 appendString:@":"];
    [temp1 appendString:temp2];
    _minTime.text = temp1;
  
}

@end
